<include file="Public/header"/> 
<include file="Public/sidebar"/>
  <!-- Content Wrapper. Contains page content -->
  <div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
      <h1>
        菜单管理
        <small>菜单列表</small>
      </h1>
      <ol class="breadcrumb">
        <li><a href="#"><i class="fa fa-dashboard"></i> Level</a></li>
        <li class="active">Here</li>
      </ol>
    </section>
    <!-- Main content -->
    <section class="content">
      <div class="box">
            <div class="box-header">
            <button class="btn btn-success" data-toggle="modal" data-target="#myModal" onclick="add()">添加菜单</button>
            </div>
            <!-- /.box-header -->
            <form action="{:U('Admin/Nav/order')}" method="post">
            <div class="box-body">
              <table id="example2" class="table table-bordered table-hover mailbox-messages">
                <thead>
                <tr>
                  <th>排序</th>
                  <th>菜单名</th>
                  <th>连接</th>
                  <th>操作</th>
                </tr>
                </thead>
                <tbody>
                <foreach name="nav" item="v">
                <tr>
                  <td><input type="text" class="form-control" style="width:40px;height:25px;" type="text" name="{$v['id']}" value="{$v['order_number']}"></td>
                  <td>{$v['_name']}</td>
                  <td>{$v['mca']}</td>
                  <td><a href="javascript:;" navId="{$v['id']}" navName="{$v['name']}" navMca="{$v['mca']}" navIco="{$v['ico']}" onclick="edit(this)">修改</a> | <a href="javascript:;" navId="{$v['id']}" navName="{$v['name']}"  onclick="add_child(this)">添加子菜单</a> | <a href="javascript:if(confirm('确定删除？'))location='{:U('Admin/Nav/delete',array('id'=>$v['id']))}'">删除</a></td>
                </tr>
                </foreach>
                <tr>
                  <th><input class="btn btn-success" type="submit" value="排序"></th>
                  <th></th>
                  <th></th>
                  <th></th>
                </tr>
                </tbody>
              </table>
            </div>
            </form>
            <!-- /.box-body -->
      </div>
      <!-- /.box -->
      <!-- Modal 添加菜单-->
      <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
        <div class="modal-dialog" role="document">
          <div class="modal-content">
            <div class="modal-header">
              <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
              <h4 class="modal-title" id="myModalLabel">添加菜单</h4>
            </div>
            <div class="modal-body">
              <form id="bjy-form" class="form-inline" action="{:U('Admin/Nav/add')}" method="post">
              <input type="hidden" name="pid" value="0">
              <table class="table table-striped table-bordered table-hover table-condensed">
                <tr>
                  <th width="12%">名称：</th>
                  <td>
                    <input class="form-control" type="text" name="name">
                  </td>
                </tr>
                <tr>
                  <th>连接：</th>
                  <td>
                    <input class="form-control" type="text" name="mca"> 输入模块/控制器/方法即可 例如 Admin/Nav/index
                  </td>
                </tr>
                <tr>
                  <th>图标：</th>
                  <td>
                    <input class="form-control" type="text" name="ico">
                    font-awesome图标 输入fa fa- 后边的即可
                  </td>
                </tr>
                <tr>
                  <th></th>
                  <td>
                    <input class="btn btn-success" type="submit" value="添加">
                  </td>
                </tr>
              </table>
            </form>
            </div>
            <div class="modal-footer">
              <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
              <button type="button" class="btn btn-primary">保存</button>
            </div>
          </div>
        </div>
      </div>
      <!-- Modal 修改菜单-->
      <div class="modal fade" id="myModalEdit" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
        <div class="modal-dialog" role="document">
          <div class="modal-content">
            <div class="modal-header">
              <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
              <h4 class="modal-title" id="myModalLabel">修改菜单</h4>
            </div>
            <div class="modal-body">
              <form id="bjy-form" class="form-inline" action="{:U('Admin/Nav/edit')}" method="post">
              <input type="hidden" name="id">
              <table class="table table-striped table-bordered table-hover table-condensed">
                <tr>
                  <th width="12%">名称：</th>
                  <td>
                    <input class="form-control" type="text" name="name">
                  </td>
                </tr>
                <tr>
                  <th>连接：</th>
                  <td>
                    <input class="form-control" type="text" name="mca"> 输入模块/控制器/方法即可 例如 Admin/Nav/index
                  </td>
                </tr>
                <tr>
                  <th>图标：</th>
                  <td>
                    <input class="form-control" type="text" name="ico">
                    font-awesome图标 输入fa fa- 后边的即可
                  </td>
                </tr>
                <tr>
                  <th></th>
                  <td>
                    <input class="btn btn-success" type="submit" value="修改">
                  </td>
                </tr>
              </table>
            </form>
            </div>
            <div class="modal-footer">
              <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
              <button type="button" class="btn btn-primary">保存</button>
            </div>
          </div>
        </div>
      </div>
    </section>
    <!-- /.content -->
  </div>
  <!-- /.content-wrapper -->
<include file="Public/footer"/>
<script>
// 添加菜单
function add(){
  $("input[name='name'],input[name='mca'],input[name='ico']").val('');
  $("input[name='pid']").val(0);
}
// 添加子菜单
function add_child(obj){
  var navId=$(obj).attr('navId');
  $("input[name='pid']").val(navId);
  $("input[name='name']").val('');
  $("input[name='mca']").val('');
  $('#myModal').modal('show');
}
// 修改菜单
function edit(obj){
  var navId=$(obj).attr('navId');
  var navName=$(obj).attr('navName');
  var navMca=$(obj).attr('navMca');
  var navIco=$(obj).attr('navIco');
  $("input[name='id']").val(navId);
  $("input[name='name']").val(navName);
  $("input[name='mca']").val(navMca);
  $("input[name='ico']").val(navIco);
  $('#myModalEdit').modal('show');
}
</script>